/**
 * create by ck on 2016/12/20.
 */
var resPackId;
var userIds;
var inList;
var outList;
$(document).ready(function() {
    resPackId  = xhTool.getQuery('iRPId');
    var DataGrid2 = new DataGridEvent();
    inList = $('#InList');
    outList = $('#OutList');
    inList.initDataGrid(baseUrl + 'Res/getPackContactUserData', {"queryParams": {"iRPId": resPackId,"type": "in"}})
        .setSelectThenEnable(['bt_out'], [], 'bs');
    outList.initDataGrid(baseUrl + 'Res/getPackContactUserData', {"queryParams": {"iRPId": resPackId,"type": "out"}}, DataGrid2)
        .setSelectThenEnable(['bt_in'], [], 'bs', DataGrid2);
    $('#bt_in').click(function(){
        userIds = outList.getDataGridSelectedFields('iUserId');
        contactQuestion('in');
    });
    $('#bt_out').click(function(){
        userIds = inList.getDataGridSelectedFields('iUserId');
        contactQuestion('out');
    });
});
//根据类型进行关联或取消关联操作
function contactQuestion(type) {
    $.post(baseUrl + 'Res/setResPackPower', {iRPId: resPackId, values: userIds, target: 'userId', type: type}, function (result) {
        $('body').append(result);
        inList.dataGridReload();
        outList.dataGridReload();
        $('#bt_in, #bt_out').setButtonDisable('bs');
    });
}